package com.base.controller;

import com.base.comm.CommContent;
import com.base.po.voip.Film;
import com.base.service.FilmService;
import com.base.service.LogsService;
import com.base.utils.IP;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 添加电影服务端
 *
 * @author f
 */
@Controller
@RequestMapping("/admin")
public class add_Film {

    @Autowired
    private LogsService logsService; // log日志
    @Autowired
    private FilmService filmService; // 电影信息

    // 添加电影信息
    @RequestMapping(value = "/toAddFilm", method = RequestMethod.POST)
    public @ResponseBody
    int toAddFilm(HttpServletRequest request, Film film) throws Exception {
        String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
        if (userid == null) return -1; // 未登录
        film.setAgentid(userid);
        film.setId(Produce.getUUID()); // 设置参数 主键ID
        film.setCreatetime(Produce.getNowDate()); // 创建时间
        film.setDatastatus(true); // 数据状态
        logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置电影信息",
                (String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
        return filmService.insertSelective(film); // 添加
    }
}
